<template>
    <div style="height: 100%; position: relative">
        <el-drawer
            :title="type === 'add' ? '新增商品' : '编辑商品'"
            :visible.sync="show_dialog"
            direction="rtl"
            size="80%"
            custom-class="demo-drawer"
            ref="drawer"
            @close="cancelForm"
        >
            <div class="demo-drawer__content" ref="content">
                <el-form :model="form" :rules="rules" v-if="show_dialog" ref="commodityDrawer">
                    <!-- <div class="infoTitle">礼品基本信息</div> -->
                    <el-form-item label="礼品图标" :label-width="formLabelWidth">
                        <el-upload
                            class="avatar-uploader"
                            action="#"
                            :auto-upload="false"
                            :on-change="
                                (val, list) => {
                                    change(val, list, 0);
                                }
                            "
                            :show-file-list="false"
                        >
                            <img v-if="imageUrl1" :src="imageUrl1" class="avatar" />
                            <i v-else class="el-icon-plus avatar-uploader-icon"></i>
                        </el-upload>
                    </el-form-item>
                    <el-form-item label="礼品名称" :label-width="formLabelWidth" prop="pgoods_name">
                        <el-input v-model="form.pgoods_name"></el-input>
                    </el-form-item>
                    <el-form-item label="礼品提供商" :label-width="formLabelWidth" prop="pgoods_business_txt">
                        <el-input
                            v-model="form.pgoods_business_txt"
                            @click.native="showStoreBox=true"
                            readonly
                        ></el-input>
                    </el-form-item>
                    <el-form-item label="商品规格"  :label-width="formLabelWidth" prop="pgoods_spec">
                        <template>
                            <el-radio v-model="form.pgoods_spec" :label="1">需要规格</el-radio>
                            <el-radio v-model="form.pgoods_spec" :label="0">不需要规格</el-radio>
                        </template>  
                    </el-form-item>    
                    <el-form-item :label-width="formLabelWidth" class="skutype-list" v-if="form.pgoods_spec==1">
                        <div class="skutype-item" v-for="(item,index) in goods_props_list" :key="index">
                            {{index==0?'主规格':'副规格'}}
                            <div>
                                <el-input v-model="item.name" placeholder="请输入规格名称"></el-input> <span v-if="index>0" @click="delSkutype(index)">删除</span>
                            </div> 
                            <div style="margin-left:20px;">
                                <el-input v-for="(detail,propsindex) in item.props"  placeholder="请输入规格属性" :key="propsindex" v-model="item.props[propsindex]"></el-input>
                                <i class="el-icon-circle-plus" style="color:#409eff;font-size:20px;" @click="addprops(index)"></i>
                                <i class="el-icon-remove" style="color:#409eff;font-size:20px;" @click="delprops(index)"></i>
                            </div>
                        </div>
 
                        <el-button type="success" @click="addSkutype">添加规格</el-button>
                        <el-button type="primary" @click="confirmSkutype">确定添加</el-button>
                          
                    </el-form-item> 
                    <el-form-item label="批量填充"  :label-width="formLabelWidth" prop="pgoods_spec" class="sku-property"  v-if="form.pgoods_spec==1">
                        <div>
                            <el-input v-model="form.pgoods_storage" placeholder="库存"></el-input>
                            <el-input v-model="form.pgoods_points" placeholder="元宝价格"></el-input>
                            <el-input v-model="form.pgoods_price" placeholder="商品原价"></el-input>
                            <el-input v-model="form.pgoods_comprice" placeholder="协议价"></el-input>
                            <el-button type="primary" @click="batchconfirm()">确定</el-button>
                        </div>
                        <div class="color-info" style="margin-top: -15px;">
                            备注：此店铺商品最低利润率为 <span class="color-danger">{{ form.min_profit_rate }}%</span>
                            <span class="color-danger" style="margin-left: 8px;">{{ pgoods_comprice_remark }}</span>
                        </div>
                        <el-table :data="goods_props" class="Skutable" border  style="width: 100%" :span-method="objectSpanMethod">
                            <el-table-column
                                v-for="(item,index) in goods_props_type"
                                :label="item"
                                align="center"
                                :key="index">
                                <template slot-scope="scope">
                                    <div>
                                        <!-- <span>{{scope.row|filter_scope(scope.column.label)}}</span> -->
                                        <el-input style="width: 120"  @focus="getchangeprops(scope.row.goods_props[scope.column.label])" @change="(newval, oldval) => changegoodsprops(newval, oldval, scope)"  v-model="scope.row.goods_props[scope.column.label]" ></el-input>
                                    </div>
                                </template>
                            </el-table-column>                        
                            <el-table-column
                                prop="goods_storage"
                                label="库存"
                                align="center"
                                #default="{ row }"
                                >
                                <el-input v-model="row.goods_storage" @blur="changeprops()" type="number"></el-input>
                            </el-table-column>
                            <el-table-column
                                prop="goods_points"
                                label="元宝价格"
                                align="center"
                                #default="{ row }"
                                >
                                <el-input  v-model="row.goods_points" type="number" ></el-input>
                            </el-table-column>  
                            <el-table-column
                                prop="goods_price"
                                label="商品原价"
                                align="center"
                                #default="{ row }"
                                >
                                <el-input  v-model="row.goods_price" type="number"></el-input>
                            </el-table-column>
                            <el-table-column
                                prop="goods_comprice"
                                label="协议价"
                                align="center"
                                #default="{ row }"
                                >
                                <el-input  v-model="row.goods_comprice" type="number"></el-input>
                            </el-table-column>   
                            <el-table-column
                                prop="goods_image"
                                label="商品图片"
                                align="center"
                                #default="{ row,$index }"
                                >
                                <el-upload
                                    class="avatar-uploader-goods"
                                    :show-file-list="false"
                                    action="#"
                                    :auto-upload="false"
                                    :on-change="(file, fileList)=>handleAvatarSuccess(file, fileList,$index)">
                                    <img v-if="row.goods_image" :src="row.goods_image" class="avatar-spec">
                                    <i v-else class="el-icon-plus avatar-uploader-goods-icon"></i>
                                </el-upload>
                            </el-table-column>                                                                                                                                          
                            <el-table-column prop="date" align="center"  label="操作" #default="{row,$index}">
                                <span style="color:#409EFF;margin-left: 5px;" v-if="row.goods_show==0" @click="row.goods_show=1">上架</span>
                                <span style="color:#409EFF;margin-left: 5px;" v-else @click="row.goods_show=0">下架</span>
                                <span style="color:#409EFF;margin-left: 5px;" v-if="row.goods_state==0" @click="row.goods_state=1">停售</span>
                                <span style="color:#409EFF;margin-left: 5px;" v-else @click="row.goods_state=0">可售</span>                                
                                <span style="color:red;margin-left: 5px;" @click="delgoodsprops($index)">删除</span>
                            </el-table-column>
                        </el-table>
                    </el-form-item>
                    <el-form-item label="礼品原价" :label-width="formLabelWidth" prop="pgoods_price"  v-if="form.pgoods_spec==0">
                        <el-input v-model="form.pgoods_price"></el-input>
                    </el-form-item>
                    <el-form-item label="协议价" :label-width="formLabelWidth" prop="pgoods_comprice"  v-if="form.pgoods_spec==0">
                        <el-input v-model="form.pgoods_comprice"></el-input>
                        <span class="color-info" style="margin-left: 8px;">
                            备注：此店铺商品最低利润率为 <span class="color-danger">{{ form.min_profit_rate }}%</span>
                        </span>
                    </el-form-item>
                    <el-form-item label="兑换元宝" :label-width="formLabelWidth" prop="pgoods_points"  v-if="form.pgoods_spec==0">
                        <el-input v-model="form.pgoods_points"></el-input>
                        <span class="color-danger" style="margin-left: 8px;">
                            {{ pgoods_comprice_remark }}
                        </span>
                    </el-form-item>
                    <!-- <el-form-item label="礼品编号" :label-width="formLabelWidth" prop="pgoods_serial">
                        <el-input v-model="form.pgoods_serial"></el-input>
                    </el-form-item> -->
                    <el-form-item label="库存" :label-width="formLabelWidth" prop="pgoods_storage"  v-if="form.pgoods_spec==0">
                        <el-input v-model="form.pgoods_storage"></el-input>
                    </el-form-item>
                    <el-form-item label="礼品标签" :label-width="formLabelWidth" prop="pgoods_tag">
                        <el-input v-model="form.pgoods_tag"></el-input>
                    </el-form-item>
                    <el-form-item label="税点" :label-width="formLabelWidth" prop="pgoods_tax_point">
                        <el-input v-model="form.pgoods_tax_point"></el-input>
                    </el-form-item>
                    <el-form-item label="商品品牌" :label-width="formLabelWidth">
                        <el-select
                            placeholder="商品品牌"
                            ref="brand_name_select"
                            @change="choose_pgoods_brand"
                            v-model="form.pgoods_brand"
                        >
                            <el-option
                                v-for="item in brand"
                                :label="item.brand_name"
                                :key="item.category_id"
                                :value="item.category_id"
                            ></el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="商品禁售" :label-width="formLabelWidth">
                        <el-switch
                            v-model="form.pgoods_state"
                            active-color="#13ce66"
                            inactive-color="#ff4949"
                            active-value="1"
                            inactive-value="0"
                        ></el-switch>
                    </el-form-item>
                    <el-form-item label="旅游商品" :label-width="formLabelWidth">
                        <el-switch
                            v-model="form.pgoods_travel"
                            active-color="#13ce66"
                            inactive-color="#ff4949"
                            active-value="1"
                            inactive-value="0"
                        ></el-switch>
                    </el-form-item>
                    <el-form-item label="内部采购商品" :label-width="formLabelWidth" prop="pgoods_inner">
                        <el-switch
                            v-model="form.pgoods_inner"
                            active-color="#13ce66"
                            inactive-color="#ff4949"
                            active-value="1"
                            inactive-value="0"
                        ></el-switch>
                    </el-form-item>
                    <el-form-item
                        v-if="form.pgoods_travel==1"
                        label="旅游商品宣传语"
                        :label-width="formLabelWidth" 
                        prop="travel_body"
                    >
                        <el-input v-model="form.travel_body"></el-input>
                    </el-form-item>
                    <el-form-item label="智能猜想" :label-width="formLabelWidth" prop="pgoods_smart_commend">
                        <el-switch
                            v-model="form.pgoods_smart_commend"
                            active-color="#13ce66"
                            inactive-color="#ff4949"
                            :active-value="1"
                            :inactive-value="2"
                        ></el-switch>
                    </el-form-item>
                    <el-form-item label="备注必填" :label-width="formLabelWidth" class="pgoods-remark">
                        <el-form-item prop="pgoods_remark_limit">
                            <el-switch
                                v-model="form.pgoods_remark_limit"
                                active-color="#13ce66"
                                inactive-color="#ff4949"
                                active-value="1"
                                inactive-value="0"
                            ></el-switch>
                        </el-form-item>
                        <el-form-item prop="pgoods_remark" v-if="form.pgoods_remark_limit == '1'">
                            <el-input v-model="form.pgoods_remark" placeholder="请输入备注语"></el-input>
                        </el-form-item>
                    </el-form-item>
                    <el-form-item label="仅限江浙沪地区购买" :label-width="formLabelWidth" prop="pgoods_area_limit">
                        <el-switch
                            v-model="form.pgoods_area_limit"
                            active-color="#13ce66"
                            inactive-color="#ff4949"
                            active-value="1"
                            inactive-value="0"
                        ></el-switch>
                    </el-form-item>

                    <!-- <div class="infoTitle">兑换要求</div> -->
                    <el-form-item label="限制每位会员兑换数量" :label-width="formLabelWidth" prop="pgoods_islimit">
                        <el-radio v-model="form.pgoods_islimit" :label="1">限制</el-radio>
                        <el-radio v-model="form.pgoods_islimit" :label="0">不限制</el-radio>
                    </el-form-item>
					<el-form-item
                        v-if="form.pgoods_islimit==1"
                        label="每会员限兑数量"
                        :label-width="formLabelWidth"
                        prop="pgoods_limitnum"
                    >
                        <div>
                            <el-input
                                type="text"
                                style="width:360px;margin-bottom:10px;"
                                v-model="form.pgoods_limitnum"
                            ></el-input>
                        </div>
                        <el-date-picker
                            v-model="pgoods_limit_starttime_formdate"
                            type="date"
                            placeholder="选择开始日期"
                            value-format="timestamp"
                        ></el-date-picker>
                        <el-date-picker
                            v-model="pgoods_limit_endtime_formdate"
                            type="date"
                            placeholder="选择结束日期"
                            value-format="timestamp"
                        ></el-date-picker>
                    </el-form-item>
                    <el-form-item label="导入第三方兑换码" :label-width="formLabelWidth">
                        <el-upload
                            style="width:400px;"
                            class="upload-demo"
                            action="#"
                            :auto-upload="false"
                            :limit="1"
                            :on-change="
                                (val, list) => {
                                    codeChange(val, list);
                                }
                            "
                            :file-list="codeFileList"
                        >
                            <el-button size="small" type="primary">点击上传</el-button>
                            <div slot="tip" class="el-upload__tip">请选择excel文件</div>
                        </el-upload>
                    </el-form-item>
                    <el-form-item label="发布平台选择" :label-width="formLabelWidth">
                        <el-button type="primary" @click="addPlant">添加平台</el-button>
                        <el-table :data="plantForm" class="plantTable" style="width: 100%">
                            <el-table-column
                                prop="name"
                                label="平台名称"
                                #default="{ row }"
                                width="200px"
                            >
                                <el-input
                                    v-model="row.storeid"
                                    @click.native="showStoreList('plantForm',row)"
                                    readonly
                                ></el-input>
                            </el-table-column>
                            <el-table-column
                                prop="num"
                                label="生成个数"
                                width="180"
                                #default="{ row }"
                            >
                                <el-input v-model="row.num"></el-input>
                            </el-table-column>
                            <el-table-column prop="date" label="截止有效期" #default="{ row }">
                                <el-date-picker
                                    v-model="row.enddate"
                                    type="date"
                                    value-format="yyyy-MM-dd"
                                    placeholder="选择日期"
                                ></el-date-picker>
                            </el-table-column>
                            <el-table-column prop="date" label="操作" #default="{$index}">
                                <el-button type="danger" @click="plantForm.splice($index,1)">删除</el-button>
                            </el-table-column>
                        </el-table>
                    </el-form-item>
                    <el-form-item label="礼品属性" :label-width="formLabelWidth">
                        <el-radio v-model="form.pgoods_virtual" label="0">实物礼品</el-radio>
                        <el-radio v-if="form.pgoods_spec!=1" v-model="form.pgoods_virtual" label="1" >虚拟礼品</el-radio>
                        <div v-show="form.pgoods_virtual=='1'">
                            有效期截止
                            <el-date-picker
                                v-model="pgoods_virtual_long_formdate"
                                type="date"
                                placeholder="选择日期"
                            ></el-date-picker>
                            <br />
                            <el-radio v-model="form.pgoods_category" label="1">话费充值</el-radio>
                            <el-radio v-model="form.pgoods_category" label="2">油卡</el-radio>    
                            <el-radio v-model="form.pgoods_category" label="3">小桔加油</el-radio> 

                            <div>
                                <el-radio v-model="form.pgoods_virtual_complete" label="1">开启</el-radio>
                                <el-radio v-model="form.pgoods_virtual_complete" label="0">关闭</el-radio>
                                <span>开启后虚拟礼品兑换即完成</span>
                            </div>
                        </div>
                        <div>
                            <el-checkbox
                                :true-label="1"
                                :false-label="0"
                                v-model="form.pgoods_hide_msg"
                            >不发送短信</el-checkbox>
                            <el-checkbox
                                :true-label="1"
                                :false-label="0"
                                v-model="form.pgoods_hide_code"
                            >隐藏系统默认兑换码</el-checkbox>
                        </div>
                    </el-form-item>
                    <el-form-item
                        label="礼品分类"
                        :label-width="formLabelWidth"
                        prop="pgoods_category_lists"
                    >
                        <el-cascader
                            v-model="form.pgoods_category_lists"
                            :options="cgy"
                            :props="category.props"
                        ></el-cascader>
                    </el-form-item>
                    <el-form-item label="礼品标签" :label-width="formLabelWidth" prop="pgoods_tags">
                        <!-- <el-checkbox-group v-model="form.pgoods_tags">
                            <el-checkbox label="1">京东专区</el-checkbox>
                            <el-checkbox label="2">会员日</el-checkbox>
                        </el-checkbox-group> -->
                        <el-checkbox-group  v-model="form.pgoods_tags" @change="handleCheckChange">
                         <el-checkbox v-for="item in pgoods_tags"   :key="item.tag_title" :label="item.tag_id">{{item.tag_title}}</el-checkbox>
                        </el-checkbox-group>
                    </el-form-item>
                    <el-form-item label="运费承担方式" :label-width="formLabelWidth">
                        <el-radio v-model="form.pgoods_freightcharge" label="0">卖家</el-radio>
                        <el-radio v-model="form.pgoods_freightcharge" label="1">买家</el-radio>
                    </el-form-item>
					<el-form-item
                        v-if="form.pgoods_freightcharge==1"
                        label="运费价格"
                        :label-width="formLabelWidth"
                    >
                        <el-input v-model="form.pgoods_freightprice"></el-input>
                    </el-form-item>
                    <el-form-item label="限制兑换时间" :label-width="formLabelWidth">
                        <el-radio v-model="form.pgoods_islimittime" label="1">限制</el-radio>
                        <el-radio v-model="form.pgoods_islimittime" label="0">不限制</el-radio>
                    </el-form-item>
					<el-form-item
                        v-if="form.pgoods_islimittime==1"
                        label="限制时间"
                        :label-width="formLabelWidth"
                        prop="order_time"
                    >
                        <el-date-picker
                            v-model="form.islimittime"
                            type="daterange"
                            range-separator="至"
                            start-placeholder="开始日期"
                            end-placeholder="结束日期"
                            value-format="timestamp"
                        ></el-date-picker>
                    </el-form-item>
                    <el-form-item label="是否支持组合兑换" :label-width="formLabelWidth">
                        <el-radio v-model="form.pgoods_ifpay" label="1">支持</el-radio>
                        <el-radio v-model="form.pgoods_ifpay" label="0">不支持</el-radio>
                    </el-form-item>
					<el-form-item
                        v-if="form.pgoods_ifpay==1"
                        label="组合兑换起始积分"
                        :label-width="formLabelWidth"
                    >
                        <el-input v-model="form.pgoods_pointnum"></el-input>
                    </el-form-item>
                    <el-form-item
                        v-if="form.pgoods_ifpay==1"
                        label="组合兑换支付金额"
                        :label-width="formLabelWidth"
                    >
                        <el-input v-model="form.pgoods_paynum"></el-input>
                    </el-form-item>
                    <el-form-item
                        v-if="form.pgoods_ifpay==1"
                        label="组合兑换最高积分"
                        :label-width="formLabelWidth"
                    >
                        <el-input v-model="form.pgoods_pointnum_max"></el-input>
                    </el-form-item>
                    <!-- <div class="infoTitle">状态设置</div> -->
                    <el-form-item label="是否上架" :label-width="formLabelWidth">
                        <el-switch
                            v-model="form.pgoods_show"
                            active-color="#13ce66"
                            inactive-color="#ff4949"
                            active-value="1"
                            inactive-value="0"
                        ></el-switch>
                    </el-form-item>
                    <el-form-item
                        :label="form.pgoods_show==1?'是否定时下架':'是否定时上架'"
                        :label-width="formLabelWidth"
                    >
                        <el-switch
                            v-model="form.pgoods_up_and_down"
                            active-color="#13ce66"
                            inactive-color="#ff4949"
                            active-value="1"
                            inactive-value="0"
                        ></el-switch>
                        <span v-if="form.pgoods_up_and_down==1">
                            &nbsp;
                            <el-date-picker
                                v-if="form.pgoods_show==1"
                                v-model="pgoods_down_time_formdate"
                                type="datetime"
                                placeholder="选择下架日期"
                                value-format="timestamp"
                            ></el-date-picker>
                            <el-date-picker
                                v-else
                                v-model="pgoods_up_time_formdate"
                                type="datetime"
                                placeholder="选择上架日期"
                                value-format="timestamp"
                            ></el-date-picker>
                        </span>
                    </el-form-item>
                    <el-form-item label="是否推荐" :label-width="formLabelWidth">
                        <el-switch
                            v-model="form.pgoods_commend"
                            active-color="#13ce66"
                            inactive-color="#ff4949"
                            :active-value="1"
                            :inactive-value="0"
                        ></el-switch>
                    </el-form-item>
                    <!-- <div class="infoTitle">SEO设置</div> -->
                    <el-form-item label="关键字" :label-width="formLabelWidth">
                        <el-input v-model="form.pgoods_keywords"></el-input>
                    </el-form-item>
                    <el-form-item label="SEO描述" :label-width="formLabelWidth">
                        <el-input
                            type="textarea"
                            style="width:360px;"
                            v-model="form.pgoods_description"
                        ></el-input>
                    </el-form-item>
                    <!-- <div class="infoTitle">其他设置</div> -->
                    <el-form-item label="礼品排序" :label-width="formLabelWidth">
                        <el-input style="width:360px;" v-model="form.pgoods_sort"></el-input>
                    </el-form-item>
                    <!-- <div class="infoTitle">礼品描述</div> -->
                    <el-form-item label="礼品描述" :label-width="formLabelWidth">
                        <tinymce
                            v-model="form.pgoods_body"
                            :height="300"
                            width="95%"
                            :uploadData="uploadData"
                        />
                    </el-form-item>
                    <el-form-item label="备注默认值" :label-width="formLabelWidth">
                        <el-input style="width:360px;" v-model="form.pgoods_buyer_msg_def"></el-input>
                    </el-form-item>
                    <!-- <el-form-item label="列表图标" :label-width="formLabelWidth">
                        <el-upload
                            class="avatar-uploader"
                            action="#"
                            :auto-upload="false"
                            :on-change="
                                (val, list) => {
                                    change(val, list, 1);
                                }
                            "
                            :show-file-list="false"
                        >
                            <img v-if="imageUrl2" :src="imageUrl2" class="avatar" />
                            <i v-else class="el-icon-plus avatar-uploader-icon"></i>
                        </el-upload>
                    </el-form-item>-->
                </el-form>
            </div>
            <div class="demo-drawer__footer">
                <el-button @click="cancelForm">取 消</el-button>
                <el-button
                    type="primary"
                    @click="handleClose"
                    :loading="loading"
                >{{ loading ? "提交中 ..." : "确 定" }}</el-button>
            </div>
        </el-drawer>
        <store-list :showStoreBox.sync="showStoreBox" @chooseStore="getStoreInfo"></store-list>
    </div>
</template>
<script>
import Tinymce from '@/components/Tinymce'
import storeList from "@/components/home/store-list.vue"
import { dateFormatter,objScreen } from "@/common/js/util"
export default {
    props: ['dialog', 'cgy','brand'],
    components: { Tinymce, storeList },
    data() {
       /*  const self = this;
        var checkTag = (rule, value, callback) => {
            if (value.length === 0) {
                return callback(new Error('请选择礼品标签'));
            }
            setTimeout(() => {
                callback();
            }, 1000);
        }; */
        var checkCgy = (rule, value, callback) => {
            if (value.length === 0) {
                return callback(new Error('请选择分类'));
            }
            setTimeout(() => {
                callback();
            }, 1000);
        };

        return {
            uploadData: {
                img_source: 'attach_pointprod'
            },
            loading: false,
            pgoods_tags: [],
            form: {
                pgoods_tags: [],
                pgoods_name: '',
                pgoods_price: '',
                pgoods_comprice: '',
                min_profit_rate: '0',
                pgoods_points: '',
                pgoods_serial: '',
                pgoods_storage: '',
                pgoods_tag: '',
                pgoods_tax_point: '',
                pgoods_brand: '',
                pgoods_state: '0',
                pgoods_travel: '',
                pgoods_inner: false,
                travel_body: '',
                pgoods_islimit: 0,
                pgoods_business_txt: '',
                pgoods_brand_obj: '',//包含名称和id
                csv: '',
                pgoods_virtual: '0',
                pgoods_virtual_long: '',
                pgoods_category: '1',//1话费 2油卡 
                pgoods_virtual_complete: '0',//开启后虚拟礼品兑换即完成
                pgoods_hide_msg: 0,
                pgoods_hide_code: 0,
                pgoods_category_list: '',
                pgoods_category_lists: [],
                pgoods_freightcharge: '0',//0卖家 1买家 
                pgoods_islimittime: '0',//0不限制 1限制
                pgoods_ifpay: '0',//是否支持组合兑换 0 不支持 1 支持
                pgoods_show: '0',
				pgoods_up_and_down: '0',
				pgoods_down_time: '',
                pgoods_up_time: '',
                pgoods_commend: 0,
                pgoods_smart_commend: 1,
                pgoods_remark_limit: '0',
                pgoods_remark: '',
                pgoods_area_limit: '0',
                pgoods_keywords: '',
                pgoods_description: '',
                pgoods_sort: '',
                pgoods_buyer_msg_def: '',
				pgoods_body: '<h1>帅哦</h1>',
				pgoods_pointnum: '',
                pgoods_paynum: '',
				pgoods_pointnum_max: '',
				pgoods_limitnum:'',
				pgoods_limit_starttime:'',
				pgoods_limit_endtime:'',
                pgoods_spec:0,
            },
            copyform:{
                pgoods_tags: [],
                pgoods_name: '',
                pgoods_price: '',
                pgoods_comprice: '',
                pgoods_points: '',
                pgoods_serial: '',
                pgoods_storage: '',
                pgoods_tag: '',
                pgoods_tax_point: '',
                pgoods_brand: '',
                pgoods_travel: '',
                pgoods_inner: false,
                travel_body: '',
                pgoods_islimit: 0,
                pgoods_business_txt: '',
                pgoods_brand_obj: '',//包含名称和id
                csv: '',
                pgoods_virtual: '0',
                pgoods_virtual_long: '',
                pgoods_category: '1',//1话费 2油卡 
                pgoods_virtual_complete: '0',//开启后虚拟礼品兑换即完成
                pgoods_hide_msg: 0,
                pgoods_hide_code: 0,
                pgoods_category_list: '',
                pgoods_category_lists: [],
                pgoods_freightcharge: '0',//0卖家 1买家 
                pgoods_islimittime: '0',//0不限制 1限制
                pgoods_ifpay: '0',//是否支持组合兑换 0 不支持 1 支持
                pgoods_show: '0',
				pgoods_up_and_down: '0',
				pgoods_down_time: '',
                pgoods_up_time: '',
                pgoods_commend: 0,
                pgoods_smart_commend: 1,
                pgoods_remark_limit: '0',
                pgoods_remark: '',
                pgoods_area_limit: '0',
                pgoods_keywords: '',
                pgoods_description: '',
                pgoods_sort: '',
                pgoods_buyer_msg_def: '',
				pgoods_body: '<h1>帅哦</h1>',
				pgoods_pointnum: '',
                pgoods_paynum: '',
				pgoods_pointnum_max: '',
				pgoods_limitnum:'',
				pgoods_limit_starttime:'',
				pgoods_limit_endtime:'',
                pgoods_spec:0, 
            },
            item_data: {},
            formLabelWidth: '160px',
            timer: null,
            show_dialog: false,//弹窗显示
            type: 'add',
            dialogImageUrl: '',
            dialogVisible: false,
            file_list: [],
            imageUrl1: '',
            imageUrl2: '',
            imageUrl3: '',
            deep: '',
            parent_arr: [{
                label: '顶级类目',
                value: '0'
            }],
            plantForm: [],
            goods_props_list:[
                {
                    name:'',
                    props:['']
                }
            ],
            goods_props:[],
            goods_props_type:[],
            radio: 1,
            giftAttr: {
                radio: '1',
                radioInfo1: {
                    checked: true
                },
                radioInfo2: {
                    checked: true,
                    date: ''
                },
            },
            content: '<h1>帅哦</h1>',
            showStoreBox: false,
            // goodsList: [],
            codeFileList: [],
            category: {
                options: [],
                props: {
					checkStrictly: true,
                    multiple: true,
                    value: 'category_id',
                    label: 'category_name',
                    children: 'child',
                    /* lazy: false,
                    lazyLoad(node, resolve) {
                        let id;
                        if (node.root) {
                            id = 0;
                            resolve(self.cgy);
                            return
                        } else {
                            id = node.value;
                        }
                        var data = {
                            page: 1,
                            pageSize: 99999
                        };
                        self.$http.get(`/admin/pointprod/index.php?act=pointCategory&op=list&parent_id=${id}`, {
                            params: data
                        }).then(res => {
                            if (res.code == 1) {
                                resolve(res.data.list)
                            } else if (res.code == 1000) {
                                resolve()
                            }
                        }).catch(err => {
                            this._message('error', err);
                        })
                    },*/
                     
                }
            },
            rules: {
                pgoods_name: [
                    { required: true, message: '请输入礼品名称', trigger: 'blur' }
                ],
                pgoods_price: [
                    { required: true, message: '请输入礼品原价', trigger: 'blur' }
                ],
                pgoods_comprice: [
                    { required: true, message: '请输入协议价', trigger: 'blur' }
                ],
                pgoods_points: [
                    { required: true, message: '请输入兑换元宝', trigger: 'blur' }
                ],
                pgoods_serial: [
                    { required: true, message: '请输入礼品编号', trigger: 'blur' }
                ],
                pgoods_storage: [
                    { required: true, message: '请输入库存', trigger: 'blur' }
                ],
                pgoods_tax_point: [
                    { required: false, message: '请输入税点', trigger: 'blur' }
                ],
                pgoods_category_lists: [
                    { required: true, validator: checkCgy, trigger: 'change' }
                ],
                pgoods_spec: [
                    { required: true, message: '请选择商品规格', trigger: 'change' }
                ],
                /* pgoods_tags: [
                    { required: true, validator: checkTag, trigger: 'change' }
                ], */
            }
        }
    },
    created() {
        this.brandList()
        /* this.cgy.forEach(item => {
            item.children = []
        })
        this.category.options = this.cgy */
	},
	computed: {
        pgoods_down_time_formdate: {
            get() {
				var long = this.form.pgoods_down_time;
				if(!long||long=="0"){
					return ''
				}
                return this.form.pgoods_down_time * 1000
            },
            set(v) {
                this.form.pgoods_down_time = v / 1000;
            }
        },
        pgoods_up_time_formdate: {
            get() {
				var long = this.form.pgoods_up_time;
				if(!long||long=="0"){
					return ''
				}
                return this.form.pgoods_up_time * 1000
            },
            set(v) {
                console.log(v)
                this.form.pgoods_up_time = v / 1000;
            }
        },
        pgoods_limit_starttime_formdate: {
            get() {
                return this.form.pgoods_limit_starttime * 1000
            },
            set(v) {
                console.log(v)
                this.form.pgoods_limit_starttime = v / 1000;
            }
        },
        pgoods_limit_endtime_formdate: {
            get() {
                return this.form.pgoods_limit_endtime * 1000
            },
            set(v) {
                console.log(v)
                this.form.pgoods_limit_endtime = v / 1000;
            }
		},
		pgoods_virtual_long_formdate:{
			get() {
				var long = this.form.pgoods_virtual_long;
				if(!long||long=="0"){
					return ''
				}
                return this.form.pgoods_virtual_long * 1000
            },
            set(v) {
                console.log(v)
                this.form.pgoods_virtual_long = v / 1000;
            }
		},
        pgoods_comprice_remark() {
            const pgoods_comprice = +this.form.pgoods_comprice || 0
            const min_profit_rate = +this.form.min_profit_rate || 0
            if (this.form.pgoods_points && +this.form.pgoods_points < (min_profit_rate / 100 + 1 ) * pgoods_comprice * 100) {
                return '提示：商品价格低于最低利润率价格，需要财务审核通过'
            }
        }
    },
    filters:{
			filter_scope(row,column){
                console.log(row)
                console.log(column)
                return row.goods_props[column]
			}
	},
    methods: {
        beforeData(id = [0]) {
            id = id[0]
            var data = {
                page: 1,
                pageSize: 99999
            };

            this.$http.get(`/admin/pointprod/index.php?act=pointCategory&op=list&parent_id=${id}`, {
                params: data
            }).then(res => {
                if (id === 0) {
                    res.data.list.forEach(item => {
                        item.children = []
                    })
                    this.category.options = res.data.list
                } else {

                }

            }).catch(err => {
                this._message('error', err);
            })
        },
        addPlant() {
            var date = {
                redeem_businessId: '',
                storeid: '',
                num: '',
                enddate: dateFormatter('YYYY-MM-DD', Date.now())
            }
            this.plantForm.push(date)
        },
        changeprops(){
            console.log(this.goods_props);
        },
        //修改sku名称
        changegoodsprops(newOrder, oldOrder, data){
            console.log(newOrder);
            console.log(data.column.label);
            console.log(this.goods_props);
            let oldprops = this.goods_props_value
            this.goods_props.forEach(item=>{
                if(item.goods_props[data.column.label] == oldprops){
                    item.goods_props[data.column.label] = newOrder
                }
            })
        },

        getchangeprops(e){
           console.log(e)
           if(e){
            this.goods_props_value = e
           }
           
        },        

        //添加规格
        addSkutype(){
            if(this.goods_props_list.length<3){
                var data =  {
                    name:'',
                    props:['']
                }

               this.goods_props_list.push(data)
            }else{
                this._message('error', '最多填写三个规格')
            }

        },
        //添加属性
        addprops(id){
            this.goods_props_list[id].props.push('');
        },
        //删除属性
        delprops(id){
            if(this.goods_props_list[id].props.length>1){
                this.goods_props_list[id].props.pop();
            }else{
                this._message('error', '最少一个属性')
            }

        },
        //确定添加规格
        confirmSkutype(){
            // console.log(this.goods_props_list);
            let goods_props_list = this.goods_props_list;
            let isempty = false;
            for(var item of goods_props_list){
                    if(item.name ==''){
                        isempty = true
                        console.log(item.name);
                    }
                    for(var detail of item.props){
                        if(detail ==''){
                        isempty = true;
                        console.log(detail);
                    }
                }
            }
            if(isempty){
                this._message('error', '规格及类别不能为空')
            }else{
                console.log(this.goods_props_type);
                console.log(this.goods_props);
                if(this.goods_props.length>0 && this.goods_props!=[]){
                    this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning'
                        }).then(() => {
                            this.skutypeSpec()
                        }).catch(() => {
                            // this.$message({
                            //     type: 'info',
                            //     message: '已取消'
                            // });          
                        });
                }else{
                    this.skutypeSpec()
                    
                }
            }
        },
        
      
      formatList(data) {
      // 深拷贝一下数据，免得层级丢失
      const array = JSON.parse(JSON.stringify(data))
      // 第一列
      let rowSpan = 1
      let temp = {}
	  // 第二列
      let rowSpan2 = 1
      let temp2 = {}
      let goods_props_type = this.goods_props_type;
	  //得到的数据循环
      array.forEach((item, index) => {
        //如果数组的下标等于0
        if (index === 0) {
          temp[item.goods_props[goods_props_type[0]]] = rowSpan
          temp2[item.goods_props[goods_props_type[0]] + item.goods_props[goods_props_type[1]]] = rowSpan2
        } else {
          const isEqual = item.goods_props[goods_props_type[0]] === array[index - 1].goods_props[goods_props_type[0]]
          temp[item.goods_props[goods_props_type[0]]] = isEqual ? (rowSpan = rowSpan + 1) : (rowSpan = 1)

          const isEqual2 = item.goods_props[goods_props_type[0]] + item.goods_props[goods_props_type[1]] === array[index - 1].goods_props[goods_props_type[0]] + array[index - 1].goods_props[goods_props_type[1]]
          temp2[item.goods_props[goods_props_type[0]] + item.goods_props[goods_props_type[1]]] = isEqual2 ? (rowSpan2 = rowSpan2 + 1) : (rowSpan2 = 1)
        }
        console.log(temp);
        console.log(temp2);
      })

      array.forEach((item) => {
        item.rowSpan = temp[item.goods_props[goods_props_type[0]]] || 0
        delete temp[item.goods_props[goods_props_type[0]]]

        item.rowSpan2 = temp2[item.goods_props[goods_props_type[0]] + item.goods_props[goods_props_type[1]]] || 0
        delete temp2[item.goods_props[goods_props_type[0]] + item.goods_props[goods_props_type[1]]]
      })

      return array
    },     
    objectSpanMethod({ row, column, rowIndex, columnIndex }) {
        const r = this.formatList(this.goods_props)
        this.tableData = r
        if (columnIndex === 0) {
        return {
          rowspan: this.tableData[rowIndex].rowSpan,
          colspan: 1
        }
      }

      if (columnIndex === 1) {
        return {
          rowspan: this.tableData[rowIndex].rowSpan2,
          colspan: 1
        }
      }
      },       


        //添加规格逻辑
        skutypeSpec(){
                var data = this.goods_props_list;
                var arrData = []
                if(data.length===1){
                        if(data[0].props.length === 0){
                        arrData.push(' ')
                    }else{
                        for(var j = 0 ;j <data[0].props.length;j++){
                            var arr = [data[0].props[j]]
                            arrData.push(arr)
                        }
                    }
                }else{
                    for(var i = data.length - 1;i>0;i--){
                    //循环调用Multiply方法   匹配多个数组
                        if(i  === data.length - 1){
                            arrData = this.Multiply(data[i-1].props,data[i].props)
                        }else{
                            arrData = this.Multiply(data[i-1].props,arrData)
                        }
                    }
                }
                this.goods_props = [];
                for(var item of arrData){
                    let list = {}
                    let name = '';
                    let goods_props = {};
                    for(var index in item){

                        goods_props[data[index].name] = item[index]
                        // goods_props.push(...obj)
                        name += ' '+ item[index] +' '
                        // console.log(item[index])
                    }
                    console.log(name)
                    list.goods_storage = 0;
                    list.goods_comprice = 0;
                    list.goods_image = '';
                    list.goods_points = 0;
                    list.goods_price = 0;
                    list.goods_show = 1;
                    list.goods_state = 0;
                    list.goods_name = this.form.pgoods_name+name;
                    list.goods_profit = 0;
                    list.goods_props = goods_props;
                    this.goods_props.push(list)
                    
                }
                this.goods_props_type = [];
                for(var item of data){
                this.goods_props_type.push(item.name)
                }
                console.log(this.goods_props);
        },
        //sku组合逻辑
        Multiply(arr1,arr2){
            var arr = []
            if(arr2.length===0 && arr1.length===0){
                arr.push(['',''])
            }else if(arr2.length===0){
                for(var i = 0 ;i<arr1.length;i++){
                    arr.push([arr1[i],''])
                }
            }else if(arr1.length===0 && Array.isArray(arr2[0])){
                for(var i = 0 ;i<arr2.length;i++){
                    arr.push(['',...arr2[i]])
                }
            }else if(arr1.length===0 && !Array.isArray(arr2[0])){
                for(var i = 0 ;i<arr2.length;i++){
                    arr.push(['',arr2[i]])
                }
            }else if(Array.isArray(arr2[0])){
                for(var i = 0 ;i<arr1.length;i++){
                    for(var j = 0 ;j<arr2.length;j++){
                        arr.push([arr1[i],...arr2[j]])
                    }
                }
            }else{
                for(var i = 0 ;i<arr1.length;i++){
                    for(var j = 0 ;j<arr2.length;j++){
                        arr.push([arr1[i],arr2[j]])
                    }
                }
            }
            return arr
        },
        //删除规格
        delSkutype(id){
            this.goods_props_list.splice(id,1);
        },
        //批量填充
        batchconfirm(){
            let data = this.goods_props;
           if(data.length>0){
            if(this.form.pgoods_storage || this.form.pgoods_points || this.form.pgoods_price || this.form.pgoods_comprice){
                for(var item of data){
                   if(this.form.pgoods_storage){
                     item.goods_storage = this.form.pgoods_storage;
                   }
                   if(this.form.pgoods_points){
                     item.goods_points = this.form.pgoods_points;
                   }
                   if(this.form.pgoods_price){
                     item.goods_price = this.form.pgoods_price;
                   }
                   if(this.form.pgoods_comprice){
                     item.goods_comprice = this.form.pgoods_comprice;
                   }                                                         
                }
             }else{
                this._message('error', '填充内容不能为空')
             } 
           }else{
                this._message('error', 'sku为空')
           } 
        },
        //删除sku
        delgoodsprops(id){
            this.goods_props.splice(id,1);
        },

        handleAvatarSuccess(file, fileList,index) {
            console.log(file)
            console.log(index)
            const isLt1M = file.size / 1024 / 1024 < 1;
            if (!isLt1M) {
              this.$message.error('上传图片大小不能超过 1MB!');
              return isLt1M; 
            }
            let formData=new FormData();
            formData.append("images",file.raw);
            formData.append("img_source",'attach_pointprod');
             this.$http.post('/common/index.php?act=upload&op=img',formData).then((res)=>{
               if(res.code==1){
                this.goods_props[index].goods_image = res.data.url
               }
            })
        },
        // beforeAvatarUpload(file,index) {


        // },        
        choose_pgoods_brand(val) {
            // this.$nextTick(() => {
            //     this.form.pgoods_brand = $(this.$refs.brand_name_select.$el).find('input')[0].value;
            // })
            this.form.pgoods_brand = val
        },
        brandList() {
        },
        showStoreList(from, row) {
            this.showStoreBox = true;
            this.storeFrom = from;
            this.storeIdItem = row;
        },
        getStoreInfo(store) {
            switch (this.storeFrom) {
                case 'plantForm':
                    this.storeIdItem.storeid = store.storeName;
                    this.storeIdItem.redeem_businessId = store.storeId;
                    break;
                default:
                    this.form.pgoods_business_txt = store.storeName;
                    this.form.pgoods_business = store.storeId;
            }
            this.getMinProfitRate(store.storeId)
        },
        // 获取商品最低利润率
        getMinProfitRate(store_id) {
            this.$http.post('/admin/pointprod/index.php?act=pointGoods&op=getMinProfitRate', { store_id }).
            then(res => {
                this.form.min_profit_rate = res.data.min_profit_rate * 100
            })
        },
        change(val, list, index) {
            this.file_list[index] = list[0]
            this['imageUrl' + (index + 1)] = URL.createObjectURL(val.raw)
            this.form.pgoods_image = val.raw;
            // this.form.
            // console.log(val, list,index)
        },
        codeChange(val, list) {
            // console.log('>>>', val, list, list[0])
            this.codeFileList = list;
            this.form.csv = val.raw;
            console.log('《》《》《》',val);
            console.log('>>>',val.raw);
            
        },
        show_dialog_fn(type, deep, row) {
            this.show_dialog = true
            this.getGoodsTags();
        },
        goodDetail(id) {
            this.$http
                .get(
                    '/admin/pointprod/index.php?act=pointCategory&op=index&category_id=' +
                    id
                )
                .then(
                    (res) => {
                        if (res.code === 1) {
                            this.form = {
                                parent_id: res.data.parent_id,
                                category_name: res.data.category_name,
                                category_sort: res.data.category_sort,
                                pgoods_sort_by: res.data.pgoods_sort_by,
                                enable: res.data.enable,
                            }
                            this.deep = res.data.deep
                            this.imageUrl1 = res.data.category_icon
                            this.imageUrl2 = res.data.category_listicon
                            this.imageUrl3 = res.data.banner_icon
                            this.parent_arr = [{
                                label: res.data.category_name,
                                value: res.data.parent_id,
                            },]
                            // this._message('success',res.msg);
                        } else {
                            this._message('error', res.msg)
                        }
                    },
                    (err) => {
                        this._message('error', res.msg)
                    }
                )
        },
        
        handleClose(done) {
            //done 用于关闭 Drawer
            done = this.$refs.drawer.closeDrawer;
            this.$refs['commodityDrawer'].validate((valid) => {
                console.log('valid', valid)
                if (valid) {
                    if (this.loading) {
                        return
                    }
                    
                    let fd = new FormData()
                    let deep
                    if (this.deep === 0) {
                        deep = this.form.parent_id === '0' ? 0 : 1
                    } else if (this.deep !== 0) {
                        deep = this.form.parent_id === '0' ? 0 : this.deep
					}
                    console.log(this.goods_props)
                    if(this.form.pgoods_spec==1 && this.goods_props && this.goods_props[0].goods_storage && this.goods_props[0].goods_points && this.goods_props[0].goods_price && this.goods_props[0].goods_comprice){
                        this.form.pgoods_storage = this.goods_props[0].goods_storage;
                        this.form.pgoods_points = this.goods_props[0].goods_points;
                        this.form.pgoods_price = this.goods_props[0].goods_price;
                        this.form.pgoods_comprice = this.goods_props[0].goods_comprice;
                    }

					var formDatas = objScreen({...this.form});
                    //pgoods_category_list字段的拼接
                    let cate_list = formDatas.pgoods_category_lists;
                    let cate_list_str = '';
                    if (cate_list && Object.prototype.toString.call(cate_list) == "[object Array]") {
                        cate_list.forEach((item, index) => {
                            if (index === 0) {
                                cate_list_str += item.pop();
                            } else {
                                cate_list_str += ',' + item.pop();
                            }
                        })
                    }
                    formDatas.pgoods_category_list = cate_list_str;
                    //pgoods_category_list字段的拼接
                    //pgoods_islimittime
                    if (formDatas.islimittime && formDatas.islimittime.length === 2) {
                        formDatas.pgoods_starttime = formDatas.islimittime[0] / 1000;
                        formDatas.pgoods_endtime = formDatas.islimittime[1] / 1000;
                    }
					//pgoods_islimittime
					//平台处理
                    this.form.nums = this.plantForm.length;
                    this.plantForm.forEach((item, index) => {
                        Object.keys(item).forEach(key => {
                            this.form[key + (index + 1)] = item[key];
                        })
                    })
                    this.goods_props.map(v => {
                        let name = ''
                        for (let i in v.goods_props) {
                            if (i != 'goods_sku') {
                                name = name + ' ' + v.goods_props[i]
                            }
                        }
                        v.goods_name = this.form.pgoods_name + ' ' + name
                    })
                    //sku
                    let spec = JSON.parse(JSON.stringify(this.goods_props));
                    let goods_props_similar = [];
                    let storage = '';
                    console.log(spec.length>0)
                    if(this.form.pgoods_spec==1){
                        if(spec.length>0){
                        //sku数据转化
                        for(var item of spec){
                            for(var index in item){
                                let title = ''
                                if(index =='goods_comprice'){
                                    title = '协议价'
                                }else if(index =='goods_image'){
                                    title = '图片'
                                }else if(index =='goods_points'){
                                    title = '元宝价格'
                                }else if(index =='goods_price'){
                                    title = '原价'
                                }else if(index =='goods_storage'){
                                    title = '库存'
                                }
                                if(item[index]==='' || item[index]===null || item[index]===undefined){
                                    this.$message.error('商品sku规格'+title+'不能为空');
                                    return; 
                                }
                                if(item[index]<0){
                                    if(index=='goods_comprice' || index=='goods_points' || index=='goods_price'|| index=='goods_storage'){
                                        this.$message.error('sku规格数据'+title+'不能小于0');
                                        return; 
                                    }
                                }
                            }

                            // item.goods_props = JSON.stringify(item.goods_props);
                            // goods_props_similar.push(item.goods_props);
                            item.goods_profit = item.goods_price - item.goods_comprice;
                            // item.goods_name = this.form.pgoods_name + item.goods_name; 
                            if(item.goods_show==1 && item.goods_state==0){
                                storage = Number(storage) +  Number(item.goods_storage) 
                            }               
                            
                        }
                        }else{
                            this.$message.error('sku规格数据不能为空');
                        }

                        formDatas.spec = JSON.stringify(spec);
                        formDatas.pgoods_storage = storage;
                    }

                    // formDatas.goods_props_similar = JSON.stringify(goods_props_similar);
                    console.log(formDatas);
                    //平台处理
                    Object.keys(formDatas).forEach(key => {
                        fd.append(key, formDatas[key])
                    })
 
                    console.log(fd);  
                    this.loading = true
                    /* fd.append('pgoods_category_list', String(this.form['pgoods_category_list'])) */
                    if (this.type === 'edit') {
                        fd.append('category_id', this.item_data.category_id)
                        this.editGood(fd).then(() => {
                            done()
                            this.$refs.content.scrollTop = 0;
                            // 动画关闭需要一定的时间
                            setTimeout(() => {
                                this.loading = false
                            }, 500)
                        })
                    } else {
                        this.addGood(fd).then(() => {
                            done()
                            // this.$refs.commodityDrawer.resetFields()
                            this.cancelForm();
                            this.$refs.content.scrollTop = 0;
                        }).catch(error => {
                            this.$message.error(`${error}`)
                        })
                        // 动画关闭需要一定的时间
                        setTimeout(() => {
                            this.loading = false
                        }, 500)
                    }
                }
            })

        },
         handleCheckChange(){
           console.log('this.form.pgoods_tags',this.form.pgoods_tags) 
        },     
        // 获取商品标签
        getGoodsTags(){
            this.$http.post('/admin/pointprod/index.php?act=pointGoods&op=getGoodsTags').then(
                    (res) => {
                        if (res.code === 1) {
                            this.pgoods_tags = res.data;
                        } else {
                           
                        }
                    },
                    (err) => {
                        this._message('error', res.msg)
                    }
                )
        },
        editGood(obj) {
            return this.$http
                .post(
                    '/admin/pointprod/index.php?act=pointCategory&op=update',
                    obj
                )
                .then(
                    (res) => {
                        if (res.code === 1) {
                            /* for(let key in this.form){
                        this.item_data[key] = this.form[key];
                    }
                    this.item_data.brand_icon = this.imageUrl1; */
                            this._message('success', res.msg)
                        } else {
                            this._message('error', res.msg)
                        }
                    },
                    (err) => {
                        this._message('error', res.msg)
                    }
                )
        },
        addGood(obj) {
            return this.$http
                .post(
                    '/admin/pointprod/index.php?act=pointGoods&op=add',
                    obj
                )
                .then(
                    (res) => {

                        if (res.code === 1) {
                            this.$parent.getListData()
                            // this.$parent.getList();
                            return Promise.resolve(res)
                        } else {
                            return Promise.reject(res.msg)
                        }
                    },
                    (err) => {
                        this._message('error', res.msg)
                    }
                )
        },
        cancelForm() {
            // console.log(2222);
            this.loading = false
            this.show_dialog = false
            this.goods_props_list=[
                {
                        name:'',
                        props:['','']
                    }
            ]
            this.goods_props=[]
            this.goods_props_type=[]
            this.pgoods_price= ''
            this.pgoods_comprice= ''
            this.pgoods_points= ''
            this.pgoods_storage= ''
            this.imageUrl1 =''           
            this.form = this.copyform
            // this.$refs.commodityDrawer.resetFields()
            // this.$nextTick(()=>{
            //   this.$refs.commodityDrawer.resetFields();//清空表单
            // }) 
            clearTimeout(this.timer)
        },
        getGoodDetail(id) {
            /* this.$http.get('/admin/pointprod/index.php?act=pointBrand&op=index&category_id='+id).then(res => {
                console.log(res)
                if (res.code === 1) {
                    this.goodDetail = res.data || {};		                }
            }) */
        },
	},
	watch: {
        show_dialog() {
            if (this.show_dialog === true) {
                this.$nextTick(() => {
                    this.$refs.content.scrollTop = 0
                })
            }
        }
    }
}
</script>

<style lang="scss" scoped>
.el-form {
    // width: 560px;
    padding-left: 10px;
}

.el-select /deep/.el-input {
    width: 360px;
}
.plantTable /deep/.el-input {
    width: auto;
}
form /deep/.el-input {
    width: 360px;
}

.demo-drawer__content {
    position: absolute;
    top: 0;
    bottom: 60px;
    width: 100%;
    overflow-y: auto;
}

/deep/.el-drawer__body {
    position: absolute;
    top: 77px;
    bottom: 0;
    width: 100%;
    overflow: auto;
    padding-bottom: 60px;
}

.demo-drawer__footer {
    position: absolute;
    bottom: 10px;
    left: 20px;
}

.avatar-uploader /deep/.el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
}

.avatar-uploader /deep/.el-upload:hover {
    border-color: #409eff;
}

.avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 178px;
    height: 178px;
    line-height: 178px;
    text-align: center;
}

.avatar {
    width: 178px;
    height: 178px;
    display: block;
}
.infoTitle {
    display: none;
    font-size: 14px;
    font-weight: 600;
    color: #5e728a;
    line-height: 50px;
    padding-left: 10px;
    background-color: #f3f5f8;
    margin-bottom: 10px;
}
.pgoods-remark {
    /deep/ .el-form-item__content {
        display: flex;
        justify-content: flex-start;
        align-items: center;
        .el-form-item {
            width: auto;
            margin-right: 10px;
            margin-bottom: 0;
            .el-form-item__content { min-height: 28px; }
            .el-input { width: 310px; }
        }
    }
}
.Skutable{
    span{
    cursor: pointer;
  }
  /deep/ .el-table__row{

 .el-input { 
    width: 100px;
    margin-left: 10px;
    }
  .el-upload{
    width:50px;
    height: 50px;
  }  
  }
} 
.skutype-list{
    padding:0 0 20px 20px;
    .skutype-item{
        margin-bottom: 10px;
        div{
            line-height: 30px;
            margin: 5px 0;
            .el-input {
            width: 170px;
            margin-right: 30px;
          }
          span{
            color: red;
            cursor: pointer;
          }
          i{
            margin-right: 5px;
            cursor: pointer;
          }
    }

    }
}
.sku-property{

    div{
        margin-bottom: 10px;
        .el-input {
                width: 150px;
                margin-right: 15px;
        }
    }   
}
.avatar-uploader-goods{
    
    margin:10px 0 0 0 !important;
}
.avatar-uploader-goods .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
  }
  .avatar-uploader-goods .el-upload:hover {
    border-color: #409EFF;
  }
  .avatar-uploader-goods-icon {
    font-size: 28px;
    border: 1px dashed #d9d9d9;
    color: #8c939d;
    width: 50px;
    height: 50px;
    line-height: 50px;
    text-align: center;
  }
  .avatar-spec {
    width: 50px;
    height: 50px;
    display: block;
  }
</style>
